using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NuoYan.Extension
{
    public static class VectorExtension
    {
        public static SerializeVector ToSerializeVector(this Vector3 vector)
        {
            return new SerializeVector(vector);
        }
        public static Vector3 ToVector3(this SerializeVector vector)
        {
            return new Vector3(vector.x, vector.y, vector.z);
        }
        /// <summary>
        /// 获得两个点之间的角度（世界的正上方为0度（Vector3.up））
        /// </summary>
        /// <param name="center">中心点</param>
        /// <param name="point">目标点</param>
        /// <param name="isCircle">是否为圆</param>
        public static float Angle(this Vector3 center, Vector3 point, bool isCircle)
        {
            float angle = Vector2.Angle(Vector3.up, point - center);
            if (!isCircle)
            {
                return angle;
            }
            else
            {
                return point.x > center.x ? angle : 360 - angle;
            }
        }
        /// <summary>
        /// vector2的小的值
        /// </summary>
        /// <param name="vector"></param>
        /// <returns>小值</returns>
        public static float Min(this Vector2 vector)
        {
            return Mathf.Min(vector.x, vector.y);
        }
        public static float Min(this Vector2Int vector)
        {
            return Mathf.Min(vector.x, vector.y);
        }
        /// <summary>
        /// vector2大的值
        /// </summary>
        /// <param name="vector"></param>
        /// <returns>大值</returns>
        public static float Max(this Vector2 vector)
        {
            return Mathf.Max(vector.x, vector.y);
        }
        public static float Max(this Vector2Int vector)
        {
            return Mathf.Max(vector.x, vector.y);
        }

        public static float Min(this Vector3 vector)
        {
            return Mathf.Min(vector.x, vector.y, vector.z);
        }
        public static float Min(this Vector3Int vector)
        {
            return Mathf.Min(vector.x, vector.y, vector.z);
        }
        public static float Max(this Vector3 vector)
        {
            return Mathf.Max(vector.x, vector.y, vector.z);
        }
        public static float Max(this Vector3Int vector)
        {
            return Mathf.Max(vector.x, vector.y, vector.z);
        }
        public static float Min(this Vector4 vector)
        {
            return Mathf.Min(vector.x, vector.y, vector.z, vector.w);
        }
        public static float Max(this Vector4 vector)
        {
            return Mathf.Max(vector.x, vector.y, vector.z, vector.w);
        }
        /// <summary>
        /// vector4的x,y的值 为小值
        /// </summary>
        /// <param name="vector4"></param>
        /// <returns></returns>
        public static Vector2 MinClamp(this Vector4 vector4)
        {
            return new Vector2(vector4.x, vector4.y);
        }

        /// <summary>
        /// vector4的z,w的值 为大值
        /// </summary>
        /// <param name="vector4"></param>
        /// <returns></returns>
        public static Vector2 MaxClamp(this Vector4 vector4)
        {
            return new Vector2(vector4.z, vector4.w);
        }
    }
    [System.Serializable]
    public class SerializeVector
    {
        public float x;
        public float y;
        public float z;
        // 默认构造函数
        public SerializeVector()
        {
            
        }
        public SerializeVector(Vector3 vector)
        {
            x = vector.x;
            y = vector.y;
            z = vector.z;
        }
        /// <summary>
        /// SerializeVector -> Vector3
        /// </summary>
        public static explicit operator Vector3(SerializeVector v)
        {
            return new Vector3(v.x, v.y, v.z);
        }
        /// <summary>
        /// Vector3 -> SerializeVector
        /// </summary>
        /// <param name="v"></param>
        public static implicit operator SerializeVector(Vector3 v)
        {
            return new SerializeVector(v);
        }
    }
}

